package com.ews.onlineexchange.controller;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.ProfessionUser;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class ProfessionUserList extends EntityQuery<ProfessionUser> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private ProfessionUser professionUser = new ProfessionUser();
	
	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ProfessionUser> entity) {
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
		restrictions.add(cb.like(entity.get("cnname"), "%" + getStringRestriction(getProfessionUser().getCnname()) + "%"));
		restrictions.add(cb.like(entity.get("username"), "%" + getStringRestriction(getProfessionUser().getUsername()) + "%"));
		return restrictions;
	}

	public ProfessionUserList() {
		setMaxResults(10);
	}

	public ProfessionUser getProfessionUser() {
		return professionUser;
	}

}
